/*
 * @Author: cqg
 * @Date: 2020-11-12 20:32:14
 * @LastEditors: xjt
 * @LastEditTime: 2020-12-25 15:13:59
 * @Description: file content
 */
import contractView from "@/views/rent/contract/view.vue";
import { getDict } from "~/utils";
import accounting from "@/views/wy-finance/bill/views/accounting/components/accounting.vue";

import { getAccountList } from "@/views/wy-finance/bill/api/accounting";
import { download } from "~/admin/api/common";
import { downloadBlob } from "~/utils/index.js";
export default {
	provide() {
		return {
			initList: this.queryData
		};
	},
	components: {
		contractView,
		accounting
	},

	beforeMount() {
		this.queryData();
	},
	data() {
		return {
			// 初始化显示状态识别符
			flag: false,
			// 核算列表请求参数
			account: {
				// 筛选列表
				filterList: [
					{
						label: "费用周期",
						inputType: "daterange",
						name: ["costPeriodStartDate", "costPeriodEndDate"]
					},
					{
						label: "账单日期",
						inputType: "daterange",
						name: ["billDateStart", "billDateEnd"]
					},
					{
						label: "结算状态",
						inputType: "dict",
						dictName: "lessor_bill_status",
						name: "billStatus",
						multiple: true,
						defaultValue: ["01"]
					}
				],
				// 表格列表数据
				tableData: [],
				// 请求参数
				params: {
					current: 1,
					size: 10,
					projectName: "",
					billStatus: ""
				},
				// 选中的数据
				selectDataArr: [],
				// 分页
				pager: {
					total: 0, // 总页数
					current: 1, // 当前页数
					size: 10 // 每页显示多少条
				},
				// 页面loading
				loading: true
			}
		};
	},
	methods: {
		// 菜单点击监听
		handleMenuClick(type) {
			switch (type) {
				case "export":
					this.exportData();
					break;
			}
		},
		changeAccountList(rentContractId) {
			this.queryData();
		},
		//导出合同列表excel表格
		exportData() {
			this.publicExport(
				"合同列表",
				"/api/collectionbill/export",
				this.account.selectDataArr
			);
		},
		// 数据请求
		queryData(params = {}) {
			this.account.loading = false;

			if (!this.flag) params.billStatus = "01";
			let requestData = {
				...this.account.params,
				...params
			};
			getAccountList(requestData)
				.then(res => {
					const { current, size, total, records } = res.data.data;
					this.flag = true;
					this.account.tableData = records;
					this.account.params = requestData;
					this.account.pager = {
						total,
						current,
						size
					};
				})
				.finally(() => {
					this.account.loading = false;
				});
		},
		// 合同状态字典值格式化
		dictVal_bill_status(row, column, cellValue) {
			let obj = getDict("lessor_bill_status").find(p => p.value == cellValue);
			if (obj) {
				return obj.label;
			}
			return "";
		}
	}
};
